<style>
    .layui-layer-content {
        width: 100%;
    }
    .am{
        width: 100%;
    }
    .am-u-md-10{
        width: 100% !important;
    }
    .am-name,.am-ipt{
        width: 258px !important;
    }
</style>
<div class="row">
    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
        <div class="widget am-cf">
            <div class="widget-head am-cf">
                <div class="widget-title am-cf">客户列表</div>
            </div>
            <div class="widget-body am-fr">

                <!-- 工具栏 -->
                <div class="page_toolbar am-margin-bottom-xs am-cf">
                    <form id="form-search" class="toolbar-form" action="">
                        <input type="hidden" name="s" value="/<?= $request->pathinfo() ?>">
                        <div class="am-u-sm-12 am-u-md-3">
                            <div class="am-form-group">
                                <div class="am-btn-toolbar">
                                    <div class="am-btn-group am-btn-group-xs">
                                        <?php if (checkPrivilege('agent.agent/goodsExport')): ?>
                                            <a class="j-export am-btn am-btn-success am-radius"
                                               href="javascript:void(0);">
                                                <i class="iconfont icon-daochu am-margin-right-xs"></i>客户数据导出
                                            </a>
                                        <?php endif; ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="am-vertical-align-middle">总记录：<?= $list->total() ?></div>
                        <div class="am-u-sm-12 am-u-md-10">
                            <div class="am fr">
                                <!--所属板块-->
                                <?php if(!$project->isEmpty()): ?>
                                <div class="am-form-group tpl-form-border-form am-fl">
                                    <select data-am-selected="{btnSize: 'sm',maxHeight: 250}" name="projectId" value=<?= $request->get('projectId') ?>>
                                        <option value="0">所属项目组</option>
                                        <?php if (!$project->isEmpty()): foreach ($project as $items): ?>
                                            <option value="<?=$items['id']?>" <?php if($request->get('projectId')==$items['id']){ echo 'selected'; }?>><?=$items['name']?></option>
                                        <?php endforeach; else: ?>
                                        <?php endif; ?>
                                    </select>
                                </div>
                                <?php endif; ?>
                                <!--意向楼盘-->
                                <div class="am-form-group tpl-form-border-form am-fl">
                                    <select data-am-selected="{btnSize: 'sm',maxHeight: 250}" name="buildId" value=<?= $request->get('buildId') ?>>
                                        <option value="0">意向楼盘</option>
                                        <?php if (!$buildlist->isEmpty()): foreach ($buildlist as $items): ?>
                                             <option value="<?=$items['id']?>" <?php if($request->get('buildId')==$items['id']){ echo 'selected'; }?>><?=$items['name']?></option>
                                        <?php endforeach; else: ?>
                                        <?php endif; ?>
                                    </select>
                                </div>
                                <!--客户状态-->
                                <div class="am-form-group tpl-form-border-form am-fl">
                                    <select data-am-selected="{btnSize: 'sm'}" name="status" value=<?= $request->get('status') ?>>
                                        <option value="0">客户状态</option>
                                        <option value="1" <?php if($request->get('status')==1){ echo 'selected'; }?>>跟进中</option>
                                        <option value="2" <?php if($request->get('status')==2){ echo 'selected'; }?>>已失效 </option>
                                        <option value="3" <?php if($request->get('status')==3){ echo 'selected'; }?>>已付订</option>
                                        <option value="4" <?php if($request->get('status')==4){ echo 'selected'; }?>>已签约</option>
                                    </select>
                                </div>
                                <!--添加时间段-->
                                <div class="am-form-group tpl-form-border-form am-fl">
                                    <input type="text" name="search_time"  class="am-form-field"  value="<?= $request->get('search_time') ?>"  readonly placeholder="选择时间"  style="width:280px">
                                </div>
                                <!--客户名称-->
                                <div class="am-form-group am-fl am-name">
                                    <div class="am-input-group am-input-group-sm tpl-form-border-form">
                                        <input type="text" class="am-form-field am-ipt" name="search"
                                               placeholder="客户名称/客户手机号" value="<?= $request->get('search') ?>">

                                    </div>
                                </div>
                                <!--录入人名称-->
                                <div class="am-form-group am-fl">
                                    <div class="am-input-group am-input-group-sm tpl-form-border-form">
                                        <input type="text" class="am-form-field" name="lururen"
                                               placeholder="录入人名称" value="<?= $request->get('lururen') ?>">
                                        <div class="am-input-group-btn">
                                            <button class="am-btn am-btn-default am-icon-search"
                                                    type="submit"></button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>

                <div class=" am-scrollable-horizontal am-u-sm-12 am-margin-top-xs">
                    <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black ">
                        <thead>
                        <tr>
                            <th>客户id</th>
                            <th>录入人</th>
                            <th>录入人电话</th>
                            <th>客户名称</th>
                            <th>客户电话</th>
                            <th>跟进人</th>
                            <th>跟进人电话</th>
                            <th>意向楼盘名称</th>
                            <th>状态</th>
                            <th>添加时间</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>

                        <?php if (!$list->isEmpty()): foreach ($list as $item): ?>
                            <tr>
                                <td class="am-text-middle">
                                    <p class="item-title"><?= $item['id'] ?></p>
                                </td>
                                <td class="am-text-middle">
                                    <p class="item-title"><?= getluruname($item['inputId']) ?></p>
                                </td>
                                <td class="am-text-middle">
                                    <p class="item-title"><?= getluruphone($item['inputId']) ?></p>
                                </td>
                                <td class="am-text-middle">
                                    <p class="item-title"><?= $item['name'] ?></p>
                                </td>
                                <td class="am-text-middle">
                                    <p class="item-title"><?= $item['phone'] ?></p>
                                </td>
                                <td class="am-text-middle">
                                    <p class="item-title"><?= getluruname($item['followUserId']) ?></p>
                                </td>
                                <td class="am-text-middle">
                                    <p class="item-title"><?= getluruphone($item['followUserId']) ?></p>
                                </td>
                                <td class="am-text-middle">
                                    <p class="item-title"><?= getgenjloupanname($item['propertiesId']) ?></p>
                                </td>
                                <td class="am-text-middle">
                                    <p class="item-title">
                                        <?php if ($item['followStatus']==1)
                                            echo "<div type='button' class='am-btn am-btn-primary am-round'>跟进中</div>";
                                        elseif($item['followStatus']==2)
                                            echo "<div type='button' class='am-btn am-btn-danger am-round'>已失效</div>";
                                        elseif($item['followStatus']==3)
                                            echo "<div type='button' class='am-btn am-btn-default am-round'>已付订</div>";
                                        else
                                            echo "<div class='am-btn am-btn-success am-round'>已签约</div>";
                                        ?>
                                    </p>
                                </td>
                                <td class="am-text-middle">
                                    <p class="item-title"><?= date('Y-m-d H:i:s',$item['createTime']) ?></p>
                                </td>
                                <td class="am-text-middle">
                                    <div class="tpl-table-black-operation">
                                        <a href="#" onclick="detail(<?= $item['id'] ?>)"
                                           class="j-move" data-id="<?= $item['id'] ?>">
                                            <i class="am-icon-arrow-right"></i> 跟进详情
                                        </a>
                                    </div>
                                </td>
                            </tr>
                        <?php endforeach; else: ?>
                            <tr>
                                <td colspan="11" class="am-text-center">暂无记录</td>
                            </tr>
                        <?php endif; ?>
                        </tbody>
                    </table>
                </div>
                <div class="am-u-lg-12 am-cf">
                    <div class="am-fr"><?= $list->render() ?> </div>
                    <div class="am-fr pagination-total am-margin-right">
                        <div class="am-vertical-align-middle">总记录：<?= $list->total() ?></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>

    //tab层
    //agent.agent/detail
    function detail(id) {
        $.ajax({
            url: "index.php?s=/admin/agent.agent/getContent",
            type: "post",
            data: {
                "id": id
            },
            success: function (res) {
                var daofang1 = "<div class='am-form-group'><div class='am-u-sm-9 am-u-end' ><div class='am-form-file'><font color='#8B636C'>图片</font>：<div class='am-form-file' style='width:650px'><div class='uploader-list am-cf'>";
                var daofang3 = "<div class='am-form-group'><div class='am-u-sm-9 am-u-end' style='width:680px'><div class='am-form-file'><div class='am-form-file'><div class='uploader-list am-cf'>";
                var daofang2 = "</div></div></div></div></div>";
                var daofang = "";
                var qianyue = "";
                var yimai = "";
                var genjin = "";
                $.each(res.data, function (i, t) {
                    var is = Number(i + 1)
                    if (t.type == 2) {
                        //到访
                        var image = "";
                        var von = "";
                        $.each(t.imageInfo, function (i, z) {
                            image += '<div class="file-item"><a href=' + z + ' title="点击查看大图" target="_blank"><img src=' + z + '></a></div>';
                        })
                        von += '</div></div> <div class="am-form-file"><font color="#8B636C">到访备注内容</font>： <div class="uploader-list am-cf">' + t.content + '';
                        daofang += daofang1 + image + von + daofang2;
                        if (daofang.length == 0) {
                            daofang = '没有数据'
                        }
                    }
                    if (t.type == 3) {
                        //签约
                        var image1 = "";
                        var von1 = "";
                        $.each(t.imageInfo, function (i, z1) {
                            console.log(z1);
                            image1 += '<div class="file-item"><a href=' + z1 + ' title="点击查看大图" target="_blank"><img src=' + z1 + '></a></div>';
                        })
                        von1 += '</div></div> <div class="am-form-file"><font color="#8B636C">签约备注内容</font>： <div class="uploader-list am-cf">' + t.content + '';
                        qianyue += daofang1 + image1 + von1 + daofang2;
                        if (qianyue.length == 0) {
                            qianyue = '没有数据'
                        }
                    }
                    if (t.type == 4) {
                        //已买
                        var image2 = "";
                        var von2 = "";
                        $.each(t.imageInfo, function (i, z2) {
                            image2 += '<div class="file-item"><a href=' + z2 + ' title="点击查看大图" target="_blank"><img src=' + z2 + '></a></div>';
                        })
                        von2 += '</div></div> <div class="am-form-file"><font color="#8B636C">已买备注内容</font>： <div class="uploader-list am-cf">' + t.content + '';
                        yimai += daofang1 + image2 + von2 + daofang2;
                    }
                    if (t.type == 1) {
                        //已买
                        var von3 = "";
                        von3 += '</div></div> <div class="am-form-file"><div class="uploader-list am-cf" ><font color="#8B636C">跟进时间</font>：' + t.createTime + '<font color="#8B636C">&nbsp;&nbsp;&nbsp;内容</font>：' + t.content + '<font color="#8B636C">&nbsp;&nbsp;&nbsp;跟进人</font>：' + t.upUser + '';
                        genjin += daofang3 + von3 + daofang2;
                    }
                })
                if (daofang.length == 0) {
                    daofang = '没有数据'
                }
                if (qianyue.length == 0) {
                    qianyue = '没有数据'
                }
                if (yimai.length == 0) {
                    yimai = '没有数据'
                }
                if (genjin.length == 0) {
                    genjin = '没有数据'
                }
                layer.tab({
                    type: 1,
                    area: ['700px', '300px'],
                    tab: [{
                        title: '到访凭证',
                        content: daofang
                    }, {
                        title: '签约备注',
                        content: qianyue
                    }, {
                        title: '已买备注',
                        content: yimai
                    }, {
                        title: '跟进信息',
                        content: genjin
                    }]
                });
            },
            error: function (e) {
                // 抛弃异常
            }
        });
    }

    $(function () {
        /**
         * 订单导出
         */
        $('.j-export').click(function () {
            var data = {};
            var formData = $('#form-search').serializeArray();
            $.each(formData, function () {
                this.name !== 's' && (data[this.name] = this.value);
            });
            window.location = "<?= url('agent.agent/goodsExport') ?>" + '&' + $.urlEncode(data);
        });
    });
</script>

